//
//  PersonalInfoViewController.m
//  share_business
//
//  Created by baidufz on 2017/8/27.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "PersonalInfoViewController.h"
#import "TextImageCell.h"
#import "TextCell.h"

@interface PersonalInfoViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (weak, nonatomic) IBOutlet TextImageCell *avatarCell;
@property (weak, nonatomic) IBOutlet TextCell *nickNameCell;
@property (weak, nonatomic) IBOutlet TextCell *addressCell;
@property (weak, nonatomic) IBOutlet TextCell *birthdayCell;
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;
@property (weak, nonatomic) IBOutlet UIPickerView *addressPicker;


@end

@implementation PersonalInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initPersonInfo];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.navigationItem.title = @"个人中心";
    [self defaultMessageRightButton];
}

- (void)initPersonInfo {

    _avatarCell.leftLabel.text = @"头像";
//    _avatarCell.rightImage
    
    [self fillingTextCell:_nickNameCell leftLabel:@"昵称" rightLabel:@""];
    [self fillingTextCell:_addressCell leftLabel:@"常驻地" rightLabel:@""];
    [self fillingTextCell:_birthdayCell leftLabel:@"生日" rightLabel:@""];
    
    _datePicker.datePickerMode = UIDatePickerModeDate;
    _datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
    [_datePicker addTarget:self action:@selector(pickDate:) forControlEvents:UIControlEventValueChanged];
    _datePicker.hidden = YES;
    _addressPicker.hidden = YES;
    [_datePicker setBorder:1 cornerRadius:0];
    [_addressPicker setBorder:1 cornerRadius:0];
    
    [_birthdayCell addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseBirthday)]];
    [_addressCell addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseAddress)]];
}


- (void)chooseBirthday {
    [self showDatePicker];
}

- (void)chooseAddress {
    [self showAddressPicker];
}

- (void)showDatePicker {
    _datePicker.hidden = NO;
    _addressPicker.hidden = YES;
}

- (void)showAddressPicker {
    _datePicker.hidden = YES;
    _addressPicker.hidden = NO;
}

- (void)hiddenPicker {
    _datePicker.hidden = YES;
    _addressPicker.hidden = YES;
}


- (void)fillingTextCell:(TextCell *)textCell leftLabel:(NSString *)left rightLabel:(NSString *)right {
    textCell.leftLabel.text = left;
    textCell.rightLabel.text = right;
}

- (void)pickDate:(UIDatePicker *)datePicker {
    // 格式化日期格式
    NSDateFormatter *formatter = [NSDateFormatter new];
    // 设置显示的格式
    [formatter setDateFormat:@"YYYY-MM-dd"];
    _birthdayCell.rightLabel.text = [formatter stringFromDate:datePicker.date];
    
}


// http://www.jianshu.com/p/403d4f7f8215 参考

// 返回多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}

// 返回每列的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return 6;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
